import {defineStore} from "pinia"

const useProductStore = defineStore('productStore', {
    state() {
        return {
            products: [],
        }
    },
    actions: {
        saveProducts(products) {
            this.products = products
        },
        getProductById(id) {
            for (const product of this.products) {
                if (product.id === id) return product
            }
        }
    },
    getters: {

    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'productStore',
                storage: window.localStorage,
                paths: ['products']
            }
        ]
    }
})

export default useProductStore